package com.weiyun.controller;

import com.weiyun.common.R;
import com.weiyun.pojo.*;
import com.weiyun.service.*;
import org.apache.ibatis.annotations.Param;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.core.annotation.Order;
import org.springframework.web.bind.annotation.*;

import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.Date;
import java.util.List;

/***
 *   @Author:weiyun
 *
 */
@RestController
@RequestMapping("/orders")
@CrossOrigin
public class OrdersController {
    @Autowired
    private OrdersService ordersService;
    @PostMapping("/createOrders")
    public R createOrders(Orders orders){
        try {
            int orders1 = ordersService.createOrders(orders);
            return R.ok().data(orders1);
        } catch (Exception e) {
            throw new RuntimeException(e);
        }

    }
    @PostMapping("/listOrdersByUserId")
    public R listOrdersByUserId(String userId){
        try {
            List<Orders> ordersList = ordersService.listOrdersByUserId(userId);
            return R.ok().data(ordersList);
        } catch (Exception e) {
            throw new RuntimeException(e);
        }
    }
    @PostMapping("/checkOutOrders")
    public R checkOutOrders(Orders orders){
        try {
            int i = ordersService.checkOutOrders(orders);
            return R.ok().data(1);
        } catch (Exception e) {
            throw new RuntimeException(e);
        }
    }
    @GetMapping("/getOrdersById/{ordersId}")
    public R getOrdersById(@PathVariable("ordersId") Integer ordersId){
        try {
            Orders ordersById = ordersService.getOrdersById(ordersId);
            return R.ok().data(ordersById);
        } catch (Exception e) {
            throw new RuntimeException(e);
        }
    }


}
